package com.kaifamiao.arrays;

import java.util.Arrays;

public class Frog {
    public static void main(String[] args) {
        // 创建一个数组
        int[] array = new int[10];
        System.out.println( Arrays.toString( array ) );

        // 动态初始化 (为数组各个位置赋予随机值)
        for (int i = 0; i < array.length; i++) {
            array[i] = (int)( Math.random() * 100 );
        }
        System.out.println( Arrays.toString( array ) );

        // 用冒泡排序对数组进行整体排序
        for ( int i = 0 ; i < array.length - 1 ; i++ ) {
            System.out.printf( "第%d轮:\n" , i + 1 );
            for (int j = 0; j < array.length - 1 - i ; j++) {
                if (array[j] < array[j+1]) {
                    array[j] ^= array[j+1];
                    array[j+1] ^= array[j];
                    array[j] ^= array[j+1];
                }
                System.out.println( "\t" + Arrays.toString( array ) );
            }
        }

        // 遍历数组
        for ( int i = 0 , len = array.length, last = len - 1 ; i < len ; i++ ) {
            System.out.printf( i < last ? "%d,\t" : "%d\n", array[i]);
        }
    }
}
